package reader;

import java.util.HashMap;
import java.util.Map;

import reader.components.ButtonRW;
import reader.components.DeviceRW;
import reader.components.FormRW;
import reader.components.FunctionRW;
import reader.components.IComponentRW;
import reader.components.LabelRW;
import reader.components.PanelRW;

import components.AbstractComponent;
import components.Button;
import components.Device;
import components.Form;
import components.Function;
import components.Label;
import components.Panel;


public class ClassMap {

    private static ClassMap instance;

    private ClassMap() {

    }

    public static ClassMap getInstance() {
        if (instance == null) {
            instance = new ClassMap();
        }
        return instance;
    }

    public IComponentRW getComponentRW(String clazzName, Map opened) {
        int index = clazzName.indexOf(".");
        if (index != -1) {
            clazzName = clazzName.substring(index + 1);
        }

        //merda de if
        if (clazzName.equals("Button")) {
            return new ButtonRW(opened);
        }
        if (clazzName.equals("Device")) {
            return new DeviceRW(opened);
        }
        if (clazzName.equals("Form")) {
            return new FormRW(opened);
        }
        if (clazzName.equals("Function")) {
            return new FunctionRW(opened);
        }
        if (clazzName.equals("Label")) {
            return new LabelRW(opened);
        }
        if (clazzName.equals("Panel")) {
            return new PanelRW(opened);
        }
        return null;
    }

    public AbstractComponent getComponent(String clazzName, AbstractComponent parent) {
        //merda de if
        if (clazzName.equals("Button")) {
            return new Button(parent);
        }
        if (clazzName.equals("Device")) {
            return new Device(parent);
        }
        if (clazzName.equals("Form")) {
            return new Form();
        }
        if (clazzName.equals("Function")) {
            return new Function(parent);
        }
        if (clazzName.equals("Label")) {
            return new Label(parent);
        }
        if (clazzName.equals("Panel")) {
            return new Panel(parent);
        }
        return parent;
    }

    public HashMap getComponetsClassMap() {
        return null;
        //return componentsClassMap;
    }
}